package com.zmm.common.valid;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.HashSet;
import java.util.Set;

/**
 * @author 900045
 * @description:
 * @name ListStringValueConstraintValidator
 * @date By 2021-08-13 14:12:57
 */
public class ListStringValueConstraintValidator implements ConstraintValidator<ListStringValue,String> {

	private Set<String> set = new HashSet<>();

	@Override
	public boolean isValid(String value, ConstraintValidatorContext context) {
		return set.contains(value);
	}

	@Override
	public void initialize(ListStringValue constraintAnnotation) {
		String[] values = constraintAnnotation.values();
		for (String value:values) {
			set.add(value);
		}
	}
}
